package org.lee.xml.inter;

import java.util.function.IntPredicate;
import java.util.stream.IntStream;

/**
 * SumNumber
 * 接口中私有方法
 *
 * @author dralee
 * @date 2022-01-25 15:34:27
 **/
public interface SumNumber {

    default int addEvents(int... nums) {
        return add(n -> n % 2 == 0, nums);
    }

    default int addOdds(int... nums) {
        return add(n -> n % 2 != 0, nums);
    }

    private int add(IntPredicate predicate, int... nums) { // java9开始允许修饰符private
        return IntStream.of(nums).filter(predicate).sum();
    }
}
